package com.wuyan.locationdog.ui.my

import android.graphics.Typeface
import androidx.fragment.app.Fragment
import com.arcsoft.commonbase.base.BaseBindingActivity
import com.arcsoft.commonbase.utils.VpAdapter
import com.flyco.tablayout.listener.OnTabSelectListener
import com.wuyan.locationdog.databinding.MyOrderActivityBinding


class MyOrderActivity : BaseBindingActivity<MyOrderActivityBinding>() {
    var fragments = mutableListOf<Fragment>()


    override fun initData() {
        setTitleText("我的订单")

        val tabTitles = mutableListOf<String>()
        tabTitles.add("全部")
        tabTitles.add("待付款")
        tabTitles.add("已取消")
        tabTitles.add("已完成")

        binding.apply {

            tabTitles.forEachIndexed { index, s ->
                fragments.add(MyOrderFragment(index))
            }
            viewPager.apply {
                adapter = VpAdapter(supportFragmentManager, fragments)
                offscreenPageLimit = fragments.size
            }

            tabLayout.setViewPager(viewPager, tabTitles.toTypedArray())
            tabLayout.getTitleView(0).apply {
                typeface = Typeface.DEFAULT_BOLD
                textSize = 15F
            }
            tabLayout.setOnTabSelectListener(object : OnTabSelectListener {
                override fun onTabSelect(position: Int) {
                    tabTitles.forEachIndexed { index, s ->
                        tabLayout.getTitleView(index).apply {
                            typeface = Typeface.DEFAULT
                            textSize = 13F
                        }
                    }
                    tabLayout.getTitleView(position).apply {
                        typeface = Typeface.DEFAULT_BOLD
                        textSize = 15F
                    }
                }

                override fun onTabReselect(position: Int) {

                }
            })


        }
    }



}